package com.bwie.controller;


import com.bwie.pojo.Goods;
import com.bwie.pojo.SearchRequest;


import com.bwie.service.SearchService;
import com.bwie.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @PostMapping("/page")
    public ResponseEntity<PageResult<Goods>> search(@RequestBody SearchRequest searchRequest){
        PageResult<Goods> page =  searchService.search(searchRequest);
        if (page == null){
            System.out.println("1111111111");
            System.out.println("2222222222");
            System.out.println("1111111111");
            System.out.println("1111111111");
            System.out.println("1111111111");
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }

        return ResponseEntity.ok(page);
    }
}
